﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.Practices.Unity;
using Intelsi.BusinessLogic;
using Intelsi.Entity;

namespace Intelsi.WB
{
	public partial class FrmListarPedidos : System.Web.UI.Page
	{
        [Dependency]
        public IPedidoBL pedidoBL { get; set; }
       // public Pedido CurrenPedido { get; set; }
        [Dependency]
        public ITrabajadorBL trabajadorBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            string userName = HttpContext.Current.User.Identity.Name;
            
            var trabajador = trabajadorBL.GetFromTrabajadorByCorreoCorporativo(userName);
            HFSuoervisor.Value = trabajador.Cargo;

            if (HFSuoervisor.Value == "Supervisor")
            {
                Dow_busPed_ger_alm.Visible = false;
                DowBuscarPedido.Visible = true;
                var valor = DowBuscarPedido.SelectedValue;

                switch (valor)
                {
                    case "Pendiente":

                        HFid.Value = trabajador.IdTrabajador.ToString();

                        GV2.Visible = false;
                        GridView2.Visible = false;
                        GridView1.Visible = true;
                        GV3_est_id.Visible = false;
                        GridView1.Columns[2].Visible = false;
                        GridView1.Columns[3].Visible = false;
                        GridView1.Columns[5].Visible = false;
                        GridView1.Columns[6].Visible = false;
                        GridView1.Columns[7].Visible = false;
                        GridView1.Columns[8].Visible = true;
                        GridView1.Columns[9].Visible = false;
                        tdFecha.Visible = false;


                        break;



                    case "Aceptado":

                        HFid.Value = trabajador.IdTrabajador.ToString();
                        GV2.Visible = false;
                        GridView2.Visible = false;
                        GridView1.Visible = true;
                        GV3_est_id.Visible = false;
                        GridView1.Columns[2].Visible = false;
                        GridView1.Columns[5].Visible = false;
                        GridView1.Columns[8].Visible = false;
                        GridView1.Columns[7].Visible = false;
                        GridView1.Columns[3].Visible = true;
                        GridView1.Columns[6].Visible = false;
                        tdFecha.Visible = false;


                        break;



                    case "Entregado":
                        HFid.Value = trabajador.IdTrabajador.ToString();
                        GridView1.Visible = false;
                        GridView2.Visible = true;
                        GV3_est_id.Visible = true;
                        GridView1.Columns[8].Visible = false;
                        GridView1.Columns[6].Visible = false;
                        GridView1.Columns[7].Visible = true;
                        GridView1.Columns[2].Visible = true;
                        GridView1.Columns[3].Visible = true;
                        GridView1.Columns[5].Visible = true;
                        tdFecha.Visible = true;
                        


                        break;



                    default:

                        break;

                }
            }
            else if (HFSuoervisor.Value == "Gerente")
            {
                DowBuscarPedido.Visible = false;
                Dow_busPed_ger_alm.Visible = true;
                var valor = Dow_busPed_ger_alm.SelectedValue;

                switch (valor)
                {
                    case "Pendiente":

                        GV2.Visible = true;
                        GridView2.Visible = false;
                        GridView1.Visible = false;
                        GV3_est_id.Visible = false;
                        GV2.Columns[2].Visible = false;
                        GV2.Columns[3].Visible = false;
                        GV2.Columns[5].Visible = false;
                        GV2.Columns[6].Visible = false;
                        GV2.Columns[7].Visible = false;
                        GV2.Columns[8].Visible = false;
                        tdFecha.Visible = false;


                        break;



                    case "Aceptado":


                        GV2.Visible = true;
                        GridView2.Visible = false;
                        GridView1.Visible = false;
                        GV3_est_id.Visible = false;
                        GV2.Columns[2].Visible = false;
                        GV2.Columns[5].Visible = false;
                        GV2.Columns[8].Visible = false;
                        GV2.Columns[7].Visible = false;

                        GV2.Columns[3].Visible = true;
                        GV2.Columns[6].Visible = false;
                        GV2.Columns[9].Visible = false;
                        tdFecha.Visible = false;


                        break;



                    case "Entregado":

                        GridView1.Visible = false;
                        GridView2.Visible = false;
                        GV2.Visible = false;
                        GV2.Visible = true;
                        GV2.Columns[8].Visible = false;
                        GV2.Columns[9].Visible = false;
                        GV2.Columns[6].Visible = false;
                        GV2.Columns[7].Visible = true;
                        GV2.Columns[2].Visible = true;
                        GV2.Columns[3].Visible = true;
                        GV2.Columns[5].Visible = true;
                        tdFecha.Visible = true;



                        break;



                    default:

                        break;

                }

            }
            else
            {

                DowBuscarPedido.Visible = false;
                Dow_busPed_ger_alm.Visible = true;
                var valor = Dow_busPed_ger_alm.SelectedValue;

                switch (valor)
                {
                    case "Pendiente":

                        GV2.Visible = false;
                        GridView2.Visible = false;
                        GridView1.Visible = false;
                        GV3_est_id.Visible = false;
                        
                        tdFecha.Visible = false;


                        break;



                    case "Aceptado":


                        GV2.Visible = true;
                        GridView2.Visible = false;
                        GridView1.Visible = false;
                        GV3_est_id.Visible = false;
                        GV2.Columns[2].Visible = false;
                        GV2.Columns[5].Visible = false;
                        GV2.Columns[8].Visible = false;
                        GV2.Columns[7].Visible = false;

                        GV2.Columns[3].Visible = true;
                        GV2.Columns[6].Visible = true;
                        GV2.Columns[9].Visible = false;
                        tdFecha.Visible = false;


                        break;



                    case "Entregado":

                        GridView1.Visible = false;
                        GridView2.Visible = false;
                        GV2.Visible = false;
                        GV2.Visible = true;
                        GV2.Columns[8].Visible = false;
                        GV2.Columns[9].Visible = false;
                        GV2.Columns[6].Visible = false;
                        GV2.Columns[7].Visible = true;
                        GV2.Columns[2].Visible = true;
                        GV2.Columns[3].Visible = true;
                        GV2.Columns[5].Visible = true;
                        tdFecha.Visible = true;



                        break;



                    default:

                        break;

                }

            }



            //if (DowBuscarPedido.SelectedValue == "Pendiente")
            //{

            //    GridView2.Visible = false;

            //    GridView1.Visible = true;
            //    GridView1.Columns[2].Visible = false;
            //    GridView1.Columns[3].Visible = false;
            //    GridView1.Columns[5].Visible = false;
            //    GridView1.Columns[6].Visible = false;
            //    GridView1.Columns[7].Visible = false;
            //    GridView1.Columns[8].Visible = true;
            //    tdFecha.Visible = false;
            //}
            //else if (DowBuscarPedido.SelectedValue == "Aceptado")
            //{
            //    GridView2.Visible = false;
            //    GridView1.Visible = true;
            //    GridView1.Columns[2].Visible = false;
            //    GridView1.Columns[5].Visible = false;
            //    GridView1.Columns[8].Visible = false;
            //    GridView1.Columns[7].Visible = false;

            //    GridView1.Columns[3].Visible = true;
            //    GridView1.Columns[6].Visible = true;
            //    tdFecha.Visible = false;
            //}

            //else
            //{
            //    GridView1.Columns[8].Visible = false;
            //    GridView1.Columns[6].Visible = false;
            //    GridView1.Columns[7].Visible = true;
            //    GridView1.Columns[2].Visible = true;
            //    GridView1.Columns[3].Visible = true;
            //    GridView1.Columns[5].Visible = true;
            //    tdFecha.Visible = true;
            //    GridView1.Visible = true;
            //}
        }

        
        protected void Buscar_estado_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = pedidoBL;
        }

        protected void btnBuscarFecha_Click(object sender, EventArgs e)
        {
                GridView1.Visible = false;
                GridView2.Visible = true;  
        }

        protected void Buscar_Fecha_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = pedidoBL;
        }

        protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = pedidoBL;
        }

        protected void btnNuevoPedido_Click(object sender, EventArgs e)
        {
            Response.Redirect("NewFrmPedido.aspx?acc=nuevo");
        }

        protected void ObjectDataSource2_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = pedidoBL;
        }

        protected void Object_esta_id_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            e.ObjectInstance = pedidoBL;
        }

              
	}
}